<template>
  <el-button type="text"
             @click="handleClick">{{title}}</el-button>
</template>

<script>
import axios from 'axios'

export default {
  name: "TemplateQuotaionCopyAction",
  inject: ["$table"],
  props: {
    record: {
      type: Object,
      default: () => { }
    },
    url: {
      type: String,
      default: null
    },
    routerName: String,
    customerType: Number,
    // 按钮名称
    title: String
  },
  methods: {
    handleClick () {
      this.$confirm("确认复制？", "提示", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.copy();
      });
    },
    async copy () {
      let response = await axios.post(this.url, {
        templateId: this.record.templateId
      });
      if (response.code === 0) {
        this.goDetail(response.data)
      } else {
        this.$message({ type: "error", message: response.message });
      }
    },
    goDetail (data) {
      this.$router.push({
        name: this.routerName,
        query: {
          customerType: this.customerType,
          mode: data.mode,
          templateId: data.templateId,
          status: data.status
        }
      });
    },
  }
}
</script>
<style scoped lang="scss">
.arrow {
  color: var(--prev-color-text-regular);
  font-size: 13px;
  padding: 0;
}
</style>